﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public class D_HRM_MP_WorkAreas : IDAL_HRM_MP_WorkAreas
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        

        public D_HRM_MP_WorkAreas()
        {

        }

        public IList<M_HRM_MP_WorkAreas> GetFull()
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_HRM_MP_WorkAreas> infoList = new List<M_HRM_MP_WorkAreas>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);

                strSQL = "SELECT work_area_seq, work_area_id, work_area_name, record_status"
                    + " FROM hrm_mp_work_areas"
                    + " WHERE record_status not like @delete_status";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_HRM_MP_WorkAreas info = new M_HRM_MP_WorkAreas();
                        info.work_area_seq = Convert.ToInt32(drc[i]["work_area_seq"]);
                        info.work_area_id = drc[i]["work_area_id"].ToString();
                        info.work_area_name = drc[i]["work_area_name"].ToString();
                        //info.scope = cn.ConvertNullInt(drc[i]["scope"]);
                        info.record_status = drc[i]["record_status"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public IList<M_HRM_MP_WorkAreas> GetList()
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_HRM_MP_WorkAreas> infoList = new List<M_HRM_MP_WorkAreas>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);

                strSQL = "SELECT work_area_seq, concat(work_area_id, ' : ', work_area_name) as work_area_name"
                    + " FROM hrm_mp_work_areas"
                    + " WHERE record_status not like @delete_status";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_HRM_MP_WorkAreas info = new M_HRM_MP_WorkAreas();
                        info.work_area_seq = Convert.ToInt32(drc[i]["work_area_seq"]);
                        info.work_area_name = drc[i]["work_area_name"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public M_HRM_MP_WorkAreas GetInfo(int seq)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_HRM_MP_WorkAreas info = new M_HRM_MP_WorkAreas();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT work_area_seq, work_area_id, work_area_name, record_status"
                    + " FROM hrm_mp_work_areas"
                    + " WHERE work_area_seq = @seq";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.work_area_seq = Convert.ToInt32(drc[0]["work_area_seq"]);
                    info.work_area_id = drc[0]["work_area_id"].ToString();
                    info.work_area_name = drc[0]["work_area_name"].ToString();
                    //info.scope = cn.ConvertNullInt(drc[0]["scope"]);
                    info.record_status = drc[0]["record_status"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }
    }
}
